import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
import axios from "axios";

var store = new Vuex.Store({
  state: {
    islogin:false,
    userintro:{}
  },
  mutations: {
    backPath: function () {
      history.back();
    },
    setLogin:function(state,value){
      state.islogin = value;
    },
    setUserintro:function(state,value){
      state.userintro = value;
    },
  },
  actions: {
    requestLoginIntro: function (state, data) {
      axios.get("/api/users/islogin")
        .then(res => {
          if(res.data.islogin){ 
            state.commit("setLogin",res.data.islogin);
            // console.log(res.data.islogin);
            state.commit("setUserintro",res.data.userintro);
          }else{
            state.commit("setLogin",res.data.islogin);
            // console.log(res.data.islogin);
          }
        });
    },
  }
});


export default store;